**************************************************************
** Title:	Cossette-Lefebvre & Daoust, 2020, French Politics*
** data:	Bélanger, Nadeau, Mahéo-Leluel and Daoust, 2018	**
** date : 	April 2020										**
**************************************************************

**************************************************************
** 					Replication files						**
**************************************************************

clear all
cd "/Users/jfd/Desktop/"
use "/Users/jfd/Desktop/Projets de recherche/Qc2018_livre/Qc2018_with_districts.dta", clear
set more off

**************************************************************
** 					Generating variables 					**
**************************************************************

*Vote choice
gen vote_choice=q6
recode vote_choice (95/99=.)

*Age
drop age
recode agecalc 999=.
gen age=agecalc
replace age=agenum if age==.

gen age_stand=(age-18)/78

*Sex
gen sex=0
replace sex=1 if qsexe==2

*Education (0=completed high school; 1=Post-secondary education but no university; 2=University completed)
replace qscol=. if qscol==99

gen education=0 if qscol < 9
replace education=0.5 if inrange(qscol, 9, 13)
replace education=1 if qscol==14 | qscol==15

gen edu_nominal=0 if qscol < 9 
replace edu_nominal=1 if inrange(qscol, 9, 13)
replace edu_nominal=2 if qscol==14 | qscol==15

*Francophone
gen franco=0
replace franco=1 if qlangue==1

*Economy
gen economy=0 if q53==2
replace economy=0.5 if q53==3
replace economy=1 if q53==1

*Ideology
gen ideology=q36_1
recode ideology (98=5) (99=5)
replace ideology=ideology/10

*Référendum 
gen OUI=0
replace OUI=1 if q26==1

*Religion 
gen religious=0 if q66==2 | q66==9
replace religious=1 if q66==1

*Place of birth
gen born_quebec=0
replace born_quebec=1 if q69==1

*Immigrant contribution (in q39a, 1=tout à fait en désaccord, but in immcont, greater values mean more ethnic nationalism so we reversed the scale)
gen immcont=1 if q39a==1
replace immcont=0.75 if q39a==2
replace immcont=0.50 if q39a==3
replace immcont=0.25 if q39a==4
replace immcont=0 if q39a==5

*Critera questions, so that greater values indicate more important
recode q22_* (98/99=.)
recode  q22_* (2=0.67) (3=0.33) (4=0)

gen ethnic_nat=(q22_1+q22_4+q22_7+q22_2+q22_3+immcont)/6

**************************************************************
** 						  Cleaning				 		   	**
**************************************************************
label variable q22_1 "Born in Quebec"
label variable q22_2 "Lived in Quebec"
label variable q22_3 "Able to speak French"
label variable q22_4 "Being Catholic"
label variable q22_5 "Respect laws and institutions"
label variable q22_6 "Feeling Québécois"
label variable q22_7 "French ancestry"
label variable q22_8 "Quebec values"

label variable ethnic_nat "Ethnic nationalism"
label variable age_stand "Age"
label variable sex "Sex (woman=1)"
label variable education "Education"
label variable franco "Francophone"
label variable religious "Religious affiliation (affiliated=1)"
label variable born_quebec "Born in Québec"
label variable OUI "Québec independence (support=1)"
label variable ideology "Left-right ideology"

label define VOTE 1"PLQ" 2"PQ" 3"CAQ" 4"QS"
label value vote_choice VOTE

*Drop non-voter
drop if vote_choice==.

**************************************************************
** 					Tables and Figures						**
**************************************************************

*Table 1
est clear 
eststo: quietly estpost sum q22_4 q22_7 q22_1 q22_2 q22_3 immcont			
esttab  using "Descriptives_Qc.rtf", cells("min mean(fmt(3)) sd(fmt(3)) max count")  label   mlabels(,titles) replace

*Figure 1
hist ethnic_nat, percent xlabel(0(.1)1)

*Figure 2
reg ethnic_nat age_stand sex education  franco religious born_quebec [pweight=pond]
est store m1, title("Model 1")
reg ethnic_nat age_stand sex education franco religious born_quebec OUI ideology  [pweight=pond]
est store m2, title("Model 2")
coefplot m1 m2 , xlabel(-.15(.05).15) legend(order(1 "Model 1" 3 "Model 2") position(6)) legend(col(2)) drop(_cons) xline(0)  ///
        grid(between glcolor(black) glpattern(dash))  
		

*Figure 3 (If you use a version < Stata 15, the colour intensity %20 will not show properly)
mlogit vote_choice ethnic_nat age_stand sex education franco religious born_quebec OUI ideology   [pweight=pond]	
margins, at(ethnic_nat=(0(0.1)1))
marginsplot,  title("") recastci(rarea) ciopt(color(%20)) ytitle("Predicted probability")  xsize(5) ylabel(0(.1).7)  legend(position(6) row(1)) plot(,label("PLQ" "PQ" "CAQ" "QS"))



**************************************************************
** 					Supplementary Material					**
**************************************************************

*Chronbach's alpha 
alpha q22_4 q22_7 q22_1 q22_2 q22_3 immcont 

*Table SM1
gsem (q22_1 q22_2 q22_3 q22_4 q22_5 q22_6 q22_7 q22_8 immcont <- ),  lclass(C 1)
est store onecluster
estat lcprob
estat lcgof


gsem (q22_1 q22_2 q22_3 q22_4 q22_5 q22_6 q22_7 q22_8 immcont <- ),  lclass(C 2)
est store twocluster
estat lcprob
estat lcgof


gsem (q22_1 q22_2 q22_3 q22_4 q22_5 q22_6 q22_7 q22_8 immcont <- ),  lclass(C 3)
est store threecluster
estat lcprob
estat lcgof


gsem (q22_1 q22_2 q22_3 q22_4 q22_5 q22_6 q22_7 q22_8 immcont <- ),  lclass(C 4)
est store fourcluster
estat lcprob
estat lcgof

estimates stats onecluster twocluster threecluster fourcluster

*Table SM2
gsem (q22_1 q22_2  q22_4   q22_7 q22_3 immcont <- ),  lclass(C 2)
estat lcprob
estat lcmean

*Table SM3 (If you use a version < Stata 15, the colour intensity %20 will not show properly)
mlogit vote_choice ethnic_nat age_stand sex education franco religious born_quebec OUI ideology   [pweight=pond]
est store m1
esttab ///
        m1   ///
			using "TableA1_qc2018.rtf", ///
			label mlabels(,titles) nogap  compress ///
			pr2  b(2) se(2) nonumbers replace  noomitted nobase 


